package 队列.数组队列;


import 动态数组.NewClassArray;

import java.util.Stack;

public class ArrayQueue<E> implements Queue<E> {
    private NewClassArray<E> array;
    public ArrayQueue(int capacity) {
        this.array = new NewClassArray(capacity);
    }
    public ArrayQueue() {
        this.array = new NewClassArray();
    }
    @Override
    public void enqueue(E e) {
        array.addLast(e);
    }
    @Override
    public E dequeue() {
        return array.deleteFirst();
    }

    @Override
    public E getFront() {
        return array.getFirst();
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }
    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append(String.format("queue: \n"));
        builder.append("front [");
        for (int i = 0; i < this.getSize(); i++) {
            builder.append(array.get(i));
            if (i != this.getSize() - 1){
                builder.append(",");
            }
        }
        builder.append("] rear");
        return builder.toString();
    }
}
